<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="../lib/net.html">

<script>
function JSONGraphData(url) {
  this.rowItemsAvailable = false;
  this._url = url;
  this._formattedDataCache = null;
}

JSONGraphData.prototype.get = function() {
  if (this._formattedDataCache) {
    return Promise.resolve(this._formattedDataCache);
  }
  var self = this;
  return net.json({url: this._url}).then(function(data) {
    // Convert timestamps to Date objects.
    data.rows.forEach(function(row) {
      row[0] = new Date(row[0] * 1000);
    });
    self._formattedDataCache = data;
    return data;
  });
};
</script>
